package com.situ.mall.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * ClassName: RedisConfig
 * Package: com.situ.mall.admin.config
 * Description:
 *
 * @Author Darling_达
 * @Create 2023-04-03 16:54
 * @Version 1.0
 */

// Redis配置类
@Configuration
public class RedisConfig {


    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();

        // 设置键
        template.setKeySerializer(new StringRedisSerializer());
        // 设置值
        template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));

        // 设置连接工厂
        template.setConnectionFactory(factory);
        return template;
    }

}
